home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d909.lha / GoldED2 / Tools / PRJSource / main.c next >
C/C++ Source or Header  |  1993-08-28  |  4KB  |  164 lines

  1. /* -----------------------------------------------------------------------------
  2.  
  3.   Example: How to read GoldED's project list.  ©1993 Dietmar Eilert. DICE:
  4.  
  5.   dcc main.c -// -o ram:ReadList
  6.  
  7.   ------------------------------------------------------------------------------
  8. */
  9.  
  10. /// "includes & prototypes"
  11.  
  12. #include <amiga20/exec/exec.h>
  13. #include <amiga20/rexx/errors.h>
  14. #include <amiga20/rexx/rxslib.h>
  15. #include <amiga20/clib/exec_protos.h>
  16. #include <amiga20/clib/rexxsyslib_protos.h>
  17.  
  18. #define Prototype extern
  19.  
  20. Prototype void   main(ULONG, char **);
  21. Prototype struct RexxMsg *SendRexxCommand(char *, char *, struct MsgPort *);
  22. Prototype void   FreeRexxCommand (struct RexxMsg *);
  23. Prototype ULONG  WaitForAnswer(struct MsgPort *, char *);
  24.  
  25. ///
  26. /// "main"
  27.  
  28. void
  29. main(argc, argv)
  30.  
  31. ULONG argc;
  32. char *argv[];
  33. {
  34.     struct MsgPort *replyPort;
  35.  
  36.     char *host = "GOLDED.1";
  37.  
  38.     if (replyPort = CreateMsgPort()) {
  39.  
  40.         if (SendRexxCommand(host, "LOCK CURRENT", replyPort)) {
  41.  
  42.             char result[80];
  43.  
  44.             if (WaitForAnswer(replyPort, result) == RC_OK) {
  45.  
  46.                 if (SendRexxCommand(host, "QUERY PRJLIST", replyPort)) {
  47.  
  48.                     if (WaitForAnswer(replyPort, result) == RC_OK) {
  49.  
  50.                         struct List *list;
  51.                         struct Node *node;
  52.  
  53.                         list = (struct List *)atol(result);
  54.  
  55.                         if (list->lh_Head->ln_Succ) {
  56.  
  57.                             for (node = list->lh_Head; node->ln_Succ; node = node->ln_Succ)
  58.                                 puts(node->ln_Name);
  59.                         }
  60.                         else
  61.                             puts("project list is empty");
  62.                     }
  63.                 }
  64.                 if (SendRexxCommand(host, "UNLOCK", replyPort))
  65.                     WaitForAnswer(replyPort, result);
  66.             }
  67.         }
  68.         DeleteMsgPort(replyPort);
  69.     }
  70.     exit(0);
  71. }
  72.  
  73. ///
  74. /// "ARexx"
  75.  
  76. /* -------------------------------------- WaitForAnswer -----------------------
  77.  
  78.   Wait for answer on previously sent message. Free message afterwards. Primary
  79.   return code is returned, the result string (if any) written to <result>.
  80.  
  81. */
  82.  
  83. ULONG
  84. WaitForAnswer(port, result)
  85.  
  86. struct MsgPort *port;
  87. char   *result;
  88. {
  89.     struct RexxMsg *rexxMsg;
  90.     ULONG  error;
  91.  
  92.     *result = NULL;
  93.  
  94.     do {
  95.         
  96.         WaitPort(port);
  97.  
  98.         if (rexxMsg = (struct RexxMsg *)GetMsg(port))
  99.             if ((error = rexxMsg->rm_Result1) == RC_OK)
  100.                 if (rexxMsg->rm_Result2)
  101.                     strcpy(result, (char *)rexxMsg->rm_Result2);
  102.  
  103.     } while (!rexxMsg);
  104.  
  105.     FreeRexxCommand(rexxMsg);
  106.     return(error);
  107. }
  108.  
  109. /* ------------------------------------- FreeRexxCommand ----------------------
  110.  
  111.  Free ARexx message
  112.  
  113. */
  114.  
  115. void
  116. FreeRexxCommand(rexxmessage)
  117.  
  118. struct RexxMsg *rexxmessage;
  119. {
  120.     if (rexxmessage->rm_Result1 == RC_OK) 
  121.         if (rexxmessage->rm_Result2)
  122.             DeleteArgstring((char *)rexxmessage->rm_Result2);
  123.  
  124.     DeleteArgstring((char *)ARG0(rexxmessage));
  125.  
  126.     DeleteRexxMsg(rexxmessage);
  127. }
  128.  
  129. /* ---------------------------------- SendRexxCommand -------------------------
  130.  
  131.  Send ARexx message
  132.  
  133. */
  134.  
  135. struct RexxMsg *
  136. SendRexxCommand(port, cmd, replyPort)
  137.  
  138. char   *cmd,   *port;
  139. struct MsgPort *replyPort;
  140. {
  141.     struct MsgPort *rexxport;
  142.     struct RexxMsg *rexx_command_message = NULL;
  143.  
  144.     Forbid();
  145.  
  146.     if (rexxport = FindPort(port)) {
  147.  
  148.         if (rexx_command_message = CreateRexxMsg(replyPort, NULL, NULL)) {
  149.  
  150.             if (rexx_command_message->rm_Args[0] = CreateArgstring(cmd, strlen(cmd))) {
  151.  
  152.                 rexx_command_message->rm_Action = RXCOMM | RXFF_RESULT;
  153.  
  154.                 PutMsg(rexxport, &rexx_command_message->rm_Node);
  155.             }
  156.         }
  157.     }
  158.  
  159.     Permit();
  160.     return(rexx_command_message);
  161. }
  162.  
  163. ///
  164.